home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr25 / pmfli100.zip / PMFLIC.C < prev    next >
C/C++ Source or Header  |  1993-03-01  |  6KB  |  245 lines

  1. //////////////////////////////////////////////////////////////////////////////
  2. // This is the source file for the PMFLIC demo program.
  3. //
  4. // Copyright 1991 - Voyager Technologies, Inc.
  5. //////////////////////////////////////////////////////////////////////////////
  6.  
  7. #define INCL_PM             /* Selectively include        */
  8. #define INCL_DOS
  9. #define INCL_GPI
  10. #include <os2.h>
  11.  
  12. #include <string.h>
  13.  
  14. //
  15. // Exported functions from the animation class library
  16. //
  17. #include <fli_ex.h>
  18.  
  19. //
  20. // Header file used in the example
  21. //
  22. #include <pmflic.h>
  23.  
  24. //
  25. // Global variables
  26. //
  27.     HWND    hwndFlic;
  28.     HAB     hab;
  29.     HMQ     hmq;
  30.  
  31. VOID cdecl main(int argc,char *argv[]);
  32. VOID WindowInitialization(VOID);
  33. MRESULT EXPENTRY MyWindowProc (HWND hwnd,USHORT msg,MPARAM mp1,MPARAM mp2);
  34. MRESULT EXPENTRY AboutDlgProc(HWND hwnd,USHORT msg,MPARAM mp1,MPARAM mp2);
  35.  
  36. VOID cdecl main(int argc,char *argv[])
  37. {
  38.     ULONG flCreate = FCF_TITLEBAR | FCF_SYSMENU | FCF_MENU | FCF_BORDER |
  39.              FCF_MINBUTTON | FCF_ICON | FCF_ACCELTABLE;
  40.     QMSG    qmsg;
  41.     RECTL   rectParent;
  42.     SHORT   x,y;
  43.     SIZEL   szBmp;
  44.     CHAR    szFlic[200];
  45.     HWND    hwndFrame;
  46.     HWND    hwndClient;
  47.  
  48.     //
  49.     // Ensure the correct number of arguments were entered
  50.     //
  51.     if (argc > 1)
  52.       strcpy(szFlic,argv[1]);
  53.     else
  54.       //
  55.       // Display the default animation
  56.       //
  57.       strcpy(szFlic,ID_VTI_FLICS);
  58.  
  59.     //
  60.     // Append an extension if one wasn't found
  61.     //
  62.     if (!strchr(szFlic,'.'))
  63.       strcat(szFlic,".FLI");
  64.  
  65.     //
  66.     // Initialize PM
  67.     //
  68.     WindowInitialization();
  69.  
  70.     //
  71.     // The message box has to be displayed after initialization
  72.     //
  73.     if (argc < 2)
  74.       //
  75.       // Display some help if no parameters were entered
  76.       //
  77.       WinMessageBox(HWND_DESKTOP,HWND_DESKTOP,
  78.             "Usage Is:\n    PMFLIC filename.fli\n","PMFLIC - 1.00",1,
  79.             MB_ENTER | MB_NOICON | MB_SYSTEMMODAL);
  80.  
  81.     hwndFrame = WinCreateStdWindow(HWND_DESKTOP,
  82.                    WS_VISIBLE,
  83.                    &flCreate,
  84.                    "VTI-Sample",
  85.                    "VTI - Animation Player",
  86.                    0L,
  87.                    (HMODULE)NULL,
  88.                    ID_FLIC,
  89.                    &hwndClient);
  90.  
  91.     if (hwndFrame == (HWND)NULL ||
  92.         hwndClient == (HWND)NULL)
  93.     return;
  94.  
  95.     //
  96.     // Find the size of the desktop
  97.     //
  98.     WinQueryWindowRect(HWND_DESKTOP,(PRECTL)&rectParent);
  99.  
  100.     //
  101.     // Initialize the size of the client area
  102.     //
  103.     szBmp.cx = 320;
  104.     szBmp.cy = 200;
  105.  
  106.     //
  107.     // Find the starting point of the client area
  108.     //
  109.     x = (SHORT)(rectParent.xRight - rectParent.xLeft) - (SHORT)szBmp.cx;
  110.     x /= 2;
  111.  
  112.     y = (SHORT)(rectParent.yTop - rectParent.yBottom) - (SHORT)szBmp.cy;
  113.     y /= 2;
  114.     rectParent.yBottom = y;
  115.     rectParent.xLeft   = x;
  116.     rectParent.yTop    = y + szBmp.cy;
  117.     rectParent.xRight  = x + szBmp.cx;
  118.  
  119.     //
  120.     // Get the location of a frame that would contain that client area
  121.     //
  122.     WinCalcFrameRect(hwndFrame,(PRECTL)&rectParent,FALSE);
  123.  
  124.     //
  125.     // Move, Size and Show the window
  126.     //
  127.     WinSetWindowPos(hwndFrame,(HWND)NULL,
  128.             (SHORT)rectParent.xLeft,(SHORT)rectParent.yBottom,
  129.             (SHORT)(rectParent.xRight - rectParent.xLeft),
  130.             (SHORT)(rectParent.yTop - rectParent.yBottom),
  131.             SWP_MOVE | SWP_SIZE | SWP_SHOW);
  132.  
  133.     //
  134.     // Create the animation control
  135.     //
  136.     hwndFlic = WinCreateWindow(hwndClient,FLICBOX_CLASS,szFlic,
  137.                    WS_VISIBLE,
  138.                    0,0,320,200,hwndClient,HWND_TOP,
  139.                    0,(PVOID)NULL,
  140.                    (PVOID)NULL);
  141.  
  142.     WinSetFocus(HWND_DESKTOP,hwndFrame);
  143.  
  144.     while (WinGetMsg(hab,&qmsg,(HWND)NULL,0,0))
  145.         WinDispatchMsg(hab,&qmsg);
  146.  
  147.     WinDestroyWindow(hwndFrame);        /* Tidy up...                   */
  148.     WinDestroyMsgQueue(hmq);            /* and                          */
  149.     WinTerminate(hab);            /* terminate the application    */
  150.  
  151.     DosExit(EXIT_PROCESS,0);
  152. }
  153.  
  154. VOID WindowInitialization()
  155. {
  156.     SIZEL   size;
  157.  
  158.     hab = WinInitialize((USHORT)NULL);
  159.     hmq = WinCreateMsgQueue(hab, 0);
  160.  
  161.     //
  162.     // Class used in the sample program
  163.     //
  164.     WinRegisterClass(hab,"VTI-Sample",MyWindowProc,
  165.              CS_SIZEREDRAW | CS_CLIPCHILDREN,0);
  166.  
  167.     //
  168.     // This call to the animation class library registers the
  169.     // animation class
  170.     //
  171.     FlicInit(hab);
  172. }
  173.  
  174. MRESULT EXPENTRY MyWindowProc (HWND hwnd,USHORT msg,MPARAM mp1,MPARAM mp2)
  175. {
  176.     HPS         hps;
  177.     RECTL    rc;
  178.     CHAR    Text[81];
  179.  
  180.     switch (msg)
  181.     {
  182.       case WM_COMMAND:
  183.     switch (SHORT1FROMMP(mp1))
  184.     {
  185.       case IDM_ABOUT:
  186.  
  187.         //
  188.         // This message tells the animation control to stop playing
  189.         //
  190.         WinSendMsg(hwndFlic,FLI_STOP,0l,0l);
  191.  
  192.         //
  193.         // Display the about dialog box
  194.         //
  195.         WinDlgBox(HWND_DESKTOP, hwnd, (PFNWP)AboutDlgProc,
  196.               (HMODULE)NULL, IDM_ABOUT, NULL);
  197.  
  198.         //
  199.         // Tell the animation control to resume animating
  200.         //
  201.         WinSendMsg(hwndFlic,FLI_START,0l,0l);
  202.  
  203.         break;
  204.  
  205.       default:
  206.         return WinDefWindowProc(hwnd,msg,mp1,mp2);
  207.     }
  208.     break;
  209.  
  210.       //
  211.       // Cause termination
  212.       //
  213.       case WM_CLOSE:
  214.     WinPostMsg(hwnd,WM_QUIT,0L,0L);
  215.     break;
  216.  
  217.       default:
  218.     return WinDefWindowProc( hwnd, msg, mp1, mp2 );
  219.     }
  220.  
  221.     return FALSE;
  222. }
  223.  
  224. //
  225. // Simple dialog procedure, nothing special
  226. //
  227. MRESULT EXPENTRY AboutDlgProc(HWND hwnd,USHORT msg,MPARAM mp1,MPARAM mp2)
  228. {
  229.     switch (msg)
  230.     {
  231.       case WM_COMMAND :
  232.         switch (COMMANDMSG(&msg)->cmd)
  233.         {
  234.             case DID_OK :
  235.             case DID_CANCEL :
  236.                  WinDismissDlg (hwnd, TRUE);
  237.                  return FALSE;
  238.         }
  239.  
  240.         break;
  241.      }
  242.  
  243.      return WinDefDlgProc (hwnd,msg,mp1,mp2);
  244. }
  245.